<%--
  Created by IntelliJ IDEA.
  User: Inch
  Date: 2020/10/1
  Time: 14:27
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Rest</title>
    <script src="${pageContext.request.contextPath}/jquery/jquery-3.5.1.js"></script>
</head>
<body>
    <input type="button" value="queryAll" onclick="queryAll();">
    <input type="button" value="queryOne" onclick="queryOne();">
    <input type="button" value="addUser" onclick="addUser();">
    <input type="button" value="updateUser" onclick="updateUser();">
    <input type="button" value="deleteUser" onclick="deleteUser();">

<script>
    function queryAll() {
        $.ajax({
            type:"get",
            url:"${pageContext.request.contextPath}/users",
            success:function (ret) {
                console.log("queryall");
                console.log(ret);
            }
        })
    }

    function queryOne() {
        $.ajax({
            type:"get",
            url:"${pageContext.request.contextPath}/users/123",
            success:function (ret) {
                console.log("queryOne");
                console.log(ret);
            }
        })
    }
    function deleteUser() {
        $.ajax({
            type:"delete",
            url:"${pageContext.request.contextPath}/users/123",
            success:function (ret) {
                console.log("Delete user");
                console.log(ret);
            }
        })
    }
    function addUser() {
        var user = {id:123,name:"hello",gender:true,birth:"2020/10/1 13:12:10"}
        $.ajax({
            type:"post",
            url:"${pageContext.request.contextPath}/users",
            data:JSON.stringify(user),
            contentType:"application/json",
            success:function (ret) {
                console.log("Add User");
                console.log(ret);
            }
        })
    }
    function updateUser() {
        var user = {id:123,name:"hello",gender:true,birth:"2020/10/1 13:12:10"}
        $.ajax({
            type:"put",
            url:"${pageContext.request.contextPath}/users",
            data:JSON.stringify(user),
            contentType:"application/json",
            success:function (ret) {
                console.log("Update User");
                console.log(ret);
            }
        })
    }

</script>
</body>
</html>
